package com.example.hp.controller;

import com.example.hp.entity.Courses;
import com.example.hp.service.CoursesService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * (Courses)表控制层
 *
 * @author makejava
 * @since 2024-12-15 16:48:38
 */
@RestController
@RequestMapping("courses")
@Tag(name = "CoursesController", description = "课程管理接口22001010907 许皓翔")
public class CoursesController {
    /**
     * 服务对象
     */
    @Resource
    private CoursesService coursesService;



    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Courses> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.coursesService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param courses 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Courses> add(@RequestBody Courses courses) {
        return ResponseEntity.ok(this.coursesService.insert(courses));
    }

    /**
     * 编辑数据
     *
     * @param courses 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    public ResponseEntity<Integer> edit(@RequestBody @Valid Courses courses) {
        return ResponseEntity.ok(this.coursesService.update(courses));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer id) {
        return ResponseEntity.ok(this.coursesService.deleteById(id));
    }


}

